function judgePerm(el, binding, vnode) {
  // locale context for vue2
  const perms = vnode.context?.$store?.state?.user?.permissions || []
  const value = binding.value
  let hasPerm = false
  if (Array.isArray(value)) {
    hasPerm = value.some((p) => perms.includes(p))
  } else if (typeof value === 'string') {
    hasPerm = perms.includes(value)
  }
  el.style.display = hasPerm ? '' : 'none'
}

export default {
  inserted(el, binding, vnode) {
    judgePerm(el, binding, vnode)
  },
  update(el, binding, vnode) {
    judgePerm(el, binding, vnode)
  },
}
